package com.ynet.middleground.user.job;

import com.ynet.middleground.user.model.MasterDataSystemModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;

import com.google.common.base.Throwables;
import com.ifp.framework.ClusterJob;
import com.ynet.core.exception.BusinessException;
import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.user.dao.UserBaseInformationMapper;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

/**
 * @program: 2019-10-12_userCenter
 * @description: 主系统定时任务
 * @author: DaiGaoLe
 * @create: 2019-11-11 15:02
 **/
@Component
public class MasterDataSystemJob extends ClusterJob {

    @Autowired
    MasterDataSystemModel masterDataSystemModel;

    // 每一分钟跑一次 测试的时候用
    //@Scheduled(cron = "0/59 * * * * ? ")
    // 每天23点执行一次：0 0 23 * * ?
    @Scheduled(cron = "0 0 23 * * ? ")
    public void getCustomerId() throws Exception {
        // 是否领导者
        if (!isLeader()) {
            IfpLogger.info("job", "程序不执行");
            return;
        }

        try {
            IfpLogger.info("job", "主数据系统定时任务开始 - " + LocalDate.now());
            masterDataSystemModel.getCustomerId();
            IfpLogger.info("job", "主数据系统定时任务结束 - " + LocalDate.now());
        } catch (BusinessException be) {
            // 获取当前方法名
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "case: {}",
                    Throwables.getStackTraceAsString(be));
            return;
        } catch (Exception e) {
            // 获取当前方法名
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "case: {}",
                Throwables.getStackTraceAsString(e));
        }
    }
}
